//
//  UIBarButtonItem+Item.m
//  BuDeJie
//
//  Created by Avril on 2020/4/6.
//  Copyright © 2020 Avril. All rights reserved.
//

#import "UIBarButtonItem+Item.h"

@implementation UIBarButtonItem (Item)

+(instancetype)itemWithImage:(UIImage *)image selectImage:(UIImage *)selectImage  target:(nullable id)target action:(SEL)action{
    
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:selectImage forState:UIControlStateSelected];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIView *view = [[UIView alloc]initWithFrame:btn.bounds];
    [view addSubview:btn];
    
    return [[UIBarButtonItem alloc]initWithCustomView:view];
    
}

+(instancetype)itemWithImage:(UIImage *)image highImage:(UIImage *)highImage  target:(nullable id)target action:(SEL)action {
   
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:image forState:UIControlStateNormal];
    [btn setImage:highImage forState:UIControlStateHighlighted];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIView *view = [[UIView alloc]initWithFrame:btn.bounds];
    [view addSubview:btn];
    
    return [[UIBarButtonItem alloc]initWithCustomView:view];
    
}

@end
